package com.easy.neo4j.repository;

import com.easy.neo4j.entry.bus.SiteReader;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface StationRepository extends Neo4jRepository<SiteReader, Long> {

    /**
     * @Author: CoolPro
     * @Date: 28/3/2024
     * @Description: 根据经纬度信息查询公交站信息
     * @Name: findAllSites
     * @param lat 经度
     * @param lng 纬度
     * @param lmt 范围单位：米
     * @return: java.util.List<com.eazy.eazydemo.entry.bus.SiteReader>
    */
    @Query("MATCH (n1:BusSite) " +
            "WITH  n1,point({latitude: toFloat(n1.LatLng[0]), longitude: toFloat(n1.LatLng[1])}) AS sitePoint, " +
            "     point({latitude: toFloat($lat), longitude: toFloat($lng)}) AS inputPoint " +
            "WITH n1, point.distance(sitePoint,inputPoint) as Distance " +
            "WHERE Distance < toFloat($lmt) " +
            "return n1")
    List<SiteReader> findAllSites(@Param("lat")String lat,@Param("lng")String lng,@Param("lmt")String lmt);


}
